package com.chen.bq;

import java.util.concurrent.ArrayBlockingQueue;

// 这组API方法，会抛出异常
public class BlockingQueueTest1 {
    public static void main(String[] args) {
        // 队列大小3
        ArrayBlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
        // 添加
        System.out.println(blockingQueue.add("a"));
        System.out.println(blockingQueue.add("b"));
        System.out.println(blockingQueue.add("c"));
        // java.lang.IllegalStateException: Queue full
        // System.out.println(blockingQueue.add("d"));
        // 查看队首元素
        System.out.println(blockingQueue.element());

        System.out.println("=========");

        // 移除
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        // java.util.NoSuchElementException
        // System.out.println(blockingQueue.remove());
    }
}
